home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Linux / SLAX 6.0.8 / slax-6.0.8.iso / slax / base / 006-devel.lzm / usr / include / kruler.h < prev    next >
Encoding:
C/C++ Source or Header  |  2005-10-10  |  13.8 KB  |  522 lines

  1. /* -*- c++ -*- */
  2. /* This file is part of the KDE libraries
  3.     Copyright (C) 1998 J÷rg Habenicht (j.habenicht@europemail.com)
  4.  
  5.     This library is free software; you can redistribute it and/or
  6.     modify it under the terms of the GNU Library General Public
  7.     License as published by the Free Software Foundation; either
  8.     version 2 of the License, or (at your option) any later version.
  9.  
  10.     This library is distributed in the hope that it will be useful,
  11.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  13.     Library General Public License for more details.
  14.  
  15.     You should have received a copy of the GNU Library General Public License
  16.     along with this library; see the file COPYING.LIB.  If not, write to
  17.     the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  18.     Boston, MA 02110-1301, USA.
  19. */
  20.  
  21. #ifndef KRULER_H
  22. #define KRULER_H
  23.  
  24. #include <qframe.h>
  25. #include <qrangecontrol.h>
  26. #include <kdelibs_export.h>
  27.  
  28. /**
  29.  * A ruler widget.
  30.  *
  31.  * The vertical ruler looks similar to this:
  32.  *
  33.  *\code
  34.  *    meters                       inches
  35.  *
  36.  *    ------   <--- end mark  ---> ------
  37.  *        --                            -
  38.  *        --   <---little mark--->     --
  39.  *        --                            -
  40.  *        --                          ---
  41.  *       ---   <---medium mark          -
  42.  *        --                           --
  43.  *        --        tiny mark---->      -
  44.  *        --                         ----
  45.  *        --                            -
  46.  *      ----   <-----big mark          --
  47.  *        --                            -
  48.  *      |>--   <--ruler pointer-->   |>--
  49.  *
  50.  * \endcode
  51.  *
  52.  * There are tiny marks, little marks, medium marks, and big marks along the
  53.  *  ruler.
  54.  *
  55.  * To receive mouse clicks or mouse moves,
  56.  * the class has to be overloaded.
  57.  *
  58.  * For performance reasons, the public methods don't call QWidget::repaint().
  59.  * (Slots do, see documentation below.)
  60.  * All the changed settings will be painted once after leaving
  61.  * to the main event loop.
  62.  * For performance painting the slot methods should be used,
  63.  * they do a fast QWidget::repaint() call after changing the values.
  64.  * For setting multiple values like minValue(), maxValue(), offset() etc.
  65.  * using the public methods is recommended
  66.  * so the widget will be painted only once when entering the main event loop.
  67.  *
  68.  * @short A ruler widget.
  69.  * @author J÷rg Habenicht
  70.  */
  71. class KDEUI_EXPORT KRuler : public QFrame
  72. {
  73.   Q_OBJECT
  74.   Q_PROPERTY( int minValue READ minValue WRITE setMinValue )
  75.   Q_PROPERTY( int maxValue READ maxValue WRITE setMaxValue )
  76.   Q_PROPERTY( int value READ value WRITE setValue )
  77.   Q_PROPERTY( bool showTinyMarks READ showTinyMarks WRITE setShowTinyMarks )
  78.   Q_PROPERTY( bool showLittleMarks READ showLittleMarks WRITE setShowLittleMarks )
  79.   Q_PROPERTY( bool showMediumMarks READ showMediumMarks WRITE setShowMediumMarks )
  80.   Q_PROPERTY( bool showBigMarks READ showBigMarks WRITE setShowBigMarks )
  81.   Q_PROPERTY( bool showPointer READ showPointer WRITE setShowPointer )
  82.   Q_PROPERTY( bool showEndLabel READ showEndLabel WRITE setShowEndLabel )
  83.   Q_PROPERTY( int tinyMarkDistance READ tinyMarkDistance WRITE setTinyMarkDistance )
  84.   Q_PROPERTY( int littleMarkDistance READ littleMarkDistance WRITE setLittleMarkDistance )
  85.   Q_PROPERTY( int mediumMarkDistance READ mediumMarkDistance WRITE setBigMarkDistance )
  86.   Q_PROPERTY( int bigMarkDistance READ bigMarkDistance WRITE setBigMarkDistance )
  87.   Q_PROPERTY( double pixelPerMark READ pixelPerMark WRITE setPixelPerMark )
  88.   Q_PROPERTY( bool lengthFixed READ lengthFixed WRITE setLengthFixed )
  89.  
  90. public:
  91.  
  92. /*
  93. #define KRULER_ROTATE_TEST KRULER_ROTATE_TEST
  94. #undef KRULER_ROTATE_TEST
  95. #ifdef KRULER_ROTATE_TEST
  96.   double xtrans, ytrans, rotate;
  97. # warning tmporaer variablen eingeschaltet
  98. #endif
  99. */
  100.  
  101.   /**
  102.    * The types of units used.
  103.    **/
  104.   enum MetricStyle { Custom=0, Pixel, Inch, Millimetres, Centimetres, Metres };
  105.  
  106.   /**
  107.    * The style (or look) of the ruler.
  108.    **/
  109.     //  enum PaintStyle { Flat, Raised, Sunken };
  110.  
  111.   /**
  112.    * Constructs a horizontal ruler.
  113.    */
  114.   KRuler(QWidget *parent=0, const char *name=0);
  115.   /**
  116.    * Constructs a ruler with orientation @p orient.
  117.    *
  118.    * @p parent, @p name and @p f are passed to QFrame.
  119.    * The default look is a raised widget
  120.    * but may be changed with the inherited QFrame methods.
  121.    *
  122.    * @param orient     Orientation of the ruler.
  123.    * @param parent     Will be handed over to QFrame.
  124.    * @param name       Will be handed over to QFrame.
  125.    * @param f          Will be handed over to QFrame.
  126.    *
  127.    **/
  128.   KRuler(Orientation orient, QWidget *parent=0, const char *name=0,
  129.      WFlags f=0);
  130.  
  131.   /**
  132.    * Constructs a ruler with orientation @p orient and initial width @p widgetWidth.
  133.    *
  134.    * The width sets the fixed width of the widget. This is useful if you
  135.    * want to draw the ruler bigger or smaller than the default size.
  136.    * Note: The size of the marks doesn't change.
  137.    * @p parent, @p name and @p f are passed to QFrame.
  138.    *
  139.    * @param orient      Orientation of the ruler.
  140.    * @param widgetWidth Fixed width of the widget.
  141.    * @param parent      Will be handed over to QFrame.
  142.    * @param name        Will be handed over to QFrame.
  143.    * @param f           Will be handed over to QFrame.
  144.    *
  145.    */
  146.   KRuler(Orientation orient, int widgetWidth, QWidget *parent=0,
  147.      const char *name=0, WFlags f=0);
  148.  
  149.   /**
  150.    * Destructor.
  151.    */
  152.   ~KRuler();
  153.  
  154.   /**
  155.    * Sets the minimal value of the ruler pointer (default is 0).
  156.    *
  157.    * This method calls update() so that the widget is painted after leaving
  158.    * to the main event loop.
  159.    *
  160.    **/
  161.   void setMinValue(int);
  162.  
  163.   /**
  164.    * Returns the minimal value of the ruler pointer.
  165.    **/
  166.   inline int minValue() const;
  167.  
  168.   /**
  169.    * Sets the maximum value of the ruler pointer (default is 100).
  170.    *
  171.    * This method calls update() so that the widget is painted after leaving
  172.    * to the main event loop.
  173.    */
  174.   void setMaxValue(int);
  175.  
  176.   /**
  177.    * Returns the maximal value of the ruler pointer.
  178.    */
  179.   inline int maxValue() const;
  180.  
  181.   /**
  182.    * Sets minimum and maximum values of the ruler pointer.
  183.    *
  184.    * This method calls update() so that the widget is painted after leaving
  185.    * to the main event loop.
  186.    */
  187.   void setRange(int min, int max);
  188.  
  189.   /**
  190.    * Sets the value of the ruler pointer.
  191.    *
  192.    * The value is indicated by painting the ruler pointer at the
  193.    * corresponding position.
  194.    * This method calls update() so that the widget is painted after leaving
  195.    * to the main event loop.
  196.    */
  197.   void setValue(int);
  198.   inline int value() const;
  199.  
  200.   /**
  201.    * Sets the distance between tiny marks.
  202.    *
  203.    * This is mostly used in the English system (inches) with distance of 1.
  204.    */
  205.   void setTinyMarkDistance(int);
  206.   /**
  207.    * Returns the distance between tiny marks.
  208.    **/
  209.   inline int tinyMarkDistance() const;
  210.  
  211.   /**
  212.    * Sets the distance between little marks.
  213.    *
  214.    * The default value is 1 in the metric system and 2 in the English (inches) system.
  215.    */
  216.   void setLittleMarkDistance(int);
  217.  
  218.   /**
  219.    * Returns the distance between little marks.
  220.    */
  221.   inline int littleMarkDistance() const;
  222.  
  223.   /**
  224.    * Sets the distance between medium marks.
  225.    *
  226.    * For English (inches) styles it defaults to twice the little mark distance.
  227.    * For metric styles it defaults to five times the little mark distance.
  228.    **/
  229.   void setMediumMarkDistance(int);
  230.   inline int mediumMarkDistance() const;
  231.  
  232.   /**
  233.    * Sets distance between big marks.
  234.    *
  235.    * For English (inches) or metric styles it is twice the medium mark distance.
  236.    **/
  237.   void setBigMarkDistance(int);
  238.   /**
  239.    * Returns the distance between big marks.
  240.    **/
  241.   inline int bigMarkDistance() const;
  242.  
  243.   /**
  244.    * Shows/hides tiny marks.
  245.    **/
  246.   void setShowTinyMarks(bool);
  247.   bool showTinyMarks() const;
  248.   /**
  249.    * Shows/hides little marks.
  250.    **/
  251.   void setShowLittleMarks(bool);
  252.   bool showLittleMarks() const;
  253.   /**
  254.    * Shows/hides medium marks.
  255.    **/
  256.   void setShowMediumMarks(bool);
  257.   bool showMediumMarks() const;
  258.   /**
  259.    * Shows/hides big marks.
  260.    **/
  261.   void setShowBigMarks(bool);
  262.   bool showBigMarks() const;
  263.   /**
  264.    * Shows/hides end marks.
  265.    **/
  266.   void setShowEndMarks(bool);
  267.   bool showEndMarks() const;
  268.   /**
  269.    * Shows/hides the pointer.
  270.    */
  271.   void setShowPointer(bool);
  272.   bool showPointer() const;
  273.  
  274.   //#### KDE4: The next 3 need to go.
  275.   /**
  276.    * @deprecated
  277.    * This method has no effect other than an update. Do not use.
  278.    **/
  279.   void setValuePerLittleMark(int) KDE_DEPRECATED;
  280.  
  281.   /**
  282.    * @deprecated
  283.    * This method has no effect other than an update. Do not use.
  284.    **/
  285.   void setValuePerMediumMark(int) KDE_DEPRECATED;
  286.  
  287.   /**
  288.    * @deprecated
  289.    * This method has no effect other than an update. Do not use.
  290.    */
  291.   void setValuePerBigMark(int) KDE_DEPRECATED;
  292.  
  293.   /**
  294.    * Show/hide number values of the little marks.
  295.    *
  296.    * Default is @p false.
  297.    **/
  298.     //  void setShowLittleMarkLabel(bool);
  299.  
  300.   /**
  301.    * Show/hide number values of the medium marks.
  302.    *
  303.    * Default is @p false.
  304.    **/
  305.     //  void setShowMediumMarkLabel(bool);
  306.  
  307.   /**
  308.    * Show/hide number values of the big marks.
  309.    *
  310.    * Default is @p false.
  311.    **/
  312.     //  void showBigMarkLabel(bool);
  313.  
  314.   /**
  315.    * Show/hide number values of the end marks.
  316.    *
  317.    * Default is @p false.
  318.    **/
  319.    void setShowEndLabel(bool);
  320.    bool showEndLabel() const;
  321.  
  322.   /**
  323.    * Sets the label this is drawn at the beginning of the visible part
  324.    * of the ruler to @p label
  325.    **/
  326.   void setEndLabel(const QString&);
  327.   QString endLabel() const;
  328.  
  329.   /**
  330.    * Sets up the necessary tasks for the provided styles.
  331.    *
  332.    * A convenience method.
  333.    **/
  334.   void setRulerMetricStyle(KRuler::MetricStyle);
  335.  
  336.   /**
  337.    * Sets the number of pixels between two base marks.
  338.    *
  339.    * Calling this method stretches or shrinks your ruler.
  340.    *
  341.    * For pixel display ( MetricStyle) the value is 10.0 marks
  342.    * per pixel ;-)
  343.    * For English (inches) it is 9.0, and for centimetres ~2.835 -> 3.0 .
  344.    * If you want to magnify your part of display, you have to
  345.    * adjust the mark distance @p here.
  346.    * Notice: The double type is only supported to give the possibility
  347.    *         of having some double values.
  348.    *         It should be used with care.  Using values below 10.0
  349.    *         shows visible jumps of markpositions (e.g. 2.345).
  350.    *         Using whole numbers is highly recommended.
  351.    * To use @p int values use setPixelPerMark((int)your_int_value);
  352.    * default: 1 mark per 10 pixels
  353.    */
  354.   void setPixelPerMark(double rate);
  355.  
  356.   /**
  357.    * Returns the number of pixels between two base marks.
  358.    **/
  359.   inline double pixelPerMark() const;
  360.  
  361.   /**
  362.    * Sets the length of the ruler, i.e. the difference between
  363.    * the begin mark and the end mark of the ruler.
  364.    *
  365.    * Same as (width() - offset())
  366.    *
  367.    * when the length is not locked, it gets adjusted with the
  368.    * length of the widget.
  369.    */
  370.   void setLength(int);
  371.   int length() const;
  372.  
  373.   /**
  374.    * Locks the length of the ruler, i.e. the difference between
  375.    * the two end marks doesn't change when the widget is resized.
  376.    *
  377.    * @param fix fixes the length, if true
  378.    */
  379.   void setLengthFixed(bool fix);
  380.   bool lengthFixed() const;
  381.  
  382.   /**
  383.    * Sets the number of pixels by which the ruler may slide up or left.
  384.    * The number of pixels moved is realive to the previous position.
  385.    * The Method makes sense for updating a ruler, which is working with
  386.    * a scrollbar.
  387.    *
  388.    * This doesn't affect the position of the ruler pointer.
  389.    * Only the visible part of the ruler is moved.
  390.    *
  391.    * @param count Number of pixel moving up or left relative to the previous position
  392.    **/
  393.   void slideUp(int count = 1);
  394.  
  395.   /**
  396.    * Sets the number of pixels by which the ruler may slide down or right.
  397.    * The number of pixels moved is realive to the previous position.
  398.    * The Method makes sense for updating a ruler, which is working with
  399.    * a scrollbar.
  400.    *
  401.    * This doesn't affect the position of the ruler pointer.
  402.    * Only the visible part of the ruler is moved.
  403.    *
  404.    * @param count Number of pixel moving up or left relative to the previous position
  405.    **/
  406.   void slideDown(int count = 1);
  407.  
  408.   /**
  409.    * Sets the ruler slide offset.
  410.    *
  411.    * This is like slideup() or slidedown() with an absolute offset
  412.    * from the start of the ruler.
  413.    *
  414.    * @param offset Number of pixel to move the ruler up or left from the beginning
  415.    **/
  416.   void setOffset(int offset);
  417.  
  418.   /**
  419.    * Returns the current ruler offset.
  420.    **/
  421.   inline int offset() const;
  422.  
  423.   int endOffset() const;
  424.  
  425. public slots:
  426.  
  427.   /**
  428.    * Sets the pointer to a new position.
  429.    *
  430.    * The offset is NOT updated.
  431.    * QWidget::repaint() is called afterwards.
  432.    **/
  433.   void slotNewValue(int);
  434.  
  435.   /**
  436.    * Sets the ruler marks to a new position.
  437.    *
  438.    * The pointer is NOT updated.
  439.    * QWidget::repaint() is called afterwards.
  440.    **/
  441.   void slotNewOffset(int);
  442.  
  443.   void slotEndOffset(int);
  444.  
  445. protected:
  446.   virtual void drawContents(QPainter *);
  447.  
  448. private:
  449.   void init();
  450.  
  451.   QRangeControl range;
  452.   Orientation dir;
  453.   int tmDist;
  454.   int lmDist;
  455.   int mmDist;
  456.   int bmDist;
  457.   int offset_;
  458.   bool showtm; /* show tiny, little, medium, big, endmarks */
  459.   bool showlm;
  460.   bool showmm;
  461.   bool showbm;
  462.   bool showem;
  463.  
  464.   // #### KDE4 : All value* and show* below should be removed, unused
  465.  
  466.   int valuelm; /* value per little, medium, big mark */
  467.   int valuemm;
  468.   int valuebm;
  469.   bool showValuelm;
  470.   bool showValuemm;
  471.   bool showValuebm;
  472.  
  473.   double ppm; /* pixel per mark */
  474.  
  475.   QString endlabel;
  476.  
  477. protected:
  478.   virtual void virtual_hook( int id, void* data );
  479. private:
  480.   class KRulerPrivate;
  481.   KRulerPrivate *d;
  482. };
  483.  
  484.  
  485. int
  486. KRuler::minValue() const
  487. { return range.minValue(); }
  488.  
  489. int
  490. KRuler::maxValue() const
  491. { return range.maxValue(); }
  492.  
  493. int
  494. KRuler::value() const
  495. { return range.value(); }
  496.  
  497. int
  498. KRuler::tinyMarkDistance() const
  499. { return tmDist; }
  500.  
  501. int
  502. KRuler::littleMarkDistance() const
  503. { return lmDist; }
  504.  
  505. int
  506. KRuler::mediumMarkDistance() const
  507. { return mmDist; }
  508.  
  509. int
  510. KRuler::bigMarkDistance() const
  511. { return bmDist; }
  512.  
  513. double
  514. KRuler::pixelPerMark() const
  515. { return ppm; }
  516.  
  517. int
  518. KRuler::offset() const
  519. { return offset_; }
  520.  
  521. #endif
  522.